'''
Created on 02/11/2012

@author: GabrielBacelar
'''

class HW5Q2(object):
    '''
    classdocs
    '''

    def __init__(self):
        '''
        Constructor
        '''
        
    def getHW5Q2(self):
        
        import QValueIteration
        self.qValueIteration = QValueIteration.QValueIteration()
        
        self.qValueIteration.rewardruns = 0
        self.qValueIteration.policyruns = 0
        self.qValueIteration.actionruns = 0
        
        self.qValueIteration.actions = ["Clockwise","Counterclockwise"]
        self.qValueIteration.nodes = ["A","B","C"]
        
        """
        Assume, the discount factor, y is 0.5 and the step size for Q-learning, a is 0.5.

        Our current Q function, Q(s,a), is as follows.
                            A         B         C
        Clockwise           2.496     3.667     2.669
        Counterclockwise    7.827     0.5       2.359
        """
        self.qValueIteration.Q = {}
        self.qValueIteration.Q["A","Clockwise"] = 2.496
        self.qValueIteration.Q["A","Counterclockwise"] = 7.827
        self.qValueIteration.Q["B","Clockwise"] = 3.667
        self.qValueIteration.Q["B","Counterclockwise"] = 0.5 
        self.qValueIteration.Q["C","Clockwise"] = 2.669
        self.qValueIteration.Q["C","Counterclockwise"] = 2.359 
        
        """
        The agent encounters the following samples.
        s     a                    s'    r
        A     Counterclockwise     B     0.0
        B     Clockwise            C     0.0
        """
        self.qValueIteration.S = {}
        self.qValueIteration.S[("A","Counterclockwise","B")] = 0.0
        self.qValueIteration.S[("B","Clockwise","C")] = 0.0
        
    def resolveHW5Q2(self):
        hw5q2.getHW5Q2()
        hw5q2.qValueIteration.gama = 0.5
        hw5q2.qValueIteration.alpha = 0.5

        #print "QValues: ", hw5q2.qValueIteration.Q
        #print "Sample: ", hw5q2.qValueIteration.S
        
        hw5q2.qValueIteration.getRunningAverage()
        
        print "QValues: ", hw5q2.qValueIteration.Q
        #print "Sample: ", hw5q2.qValueIteration.S
        
        
        
        """        
        QValues:  {
        ('A', 'Clockwise'): 2.496
        ('A', 'Counterclockwise'): 4.8302499999999995
        ('B', 'Clockwise'): 2.50075
        ('B', 'Counterclockwise'): 0.5
        ('C', 'Clockwise'): 2.669
        ('C', 'Counterclockwise'): 2.359
        }
        """
        
hw5q2 = HW5Q2()
hw5q2.resolveHW5Q2()

